1
2
3
4
5
6
7
8
9 package ca.uhn.cache.util;
10
11 import org.jmock.Mock;
12 import org.jmock.cglib.MockObjectTestCase;
13 import org.jmock.core.constraint.IsNull;
14
15 /***
16 * TODO complete javadoc for
17 *
18 * @author <a href="mailto:alexei.guevara@uhn.on.ca">Alexei Guevara</a>
19 * @version $Revision: 1.1 $ updated on $Date: 2005/01/24 22:52:01 $ by $Author: bryan_tripp $
20 */
21 public class MultiDispatchTest extends MockObjectTestCase {
22
23 static class A {}
24 static class A1 extends A {}
25 static class A2 extends A {}
26 static class A3 extends A {}
27 static class Callee {
28 public Object methodA( A theA) { return null; };
29 public Object methodA( A1 theA1) { return null; };
30 public Object methodA( A2 theA2) { return null; };
31 public Object methodA( A3 theA3) { return null; };
32
33 public Object methodB( Object theObj, A theA ) { return null; };
34 public Object methodB( Object theObj, A1 theA1 ) { return null; };
35 public Object methodB( Object theObj, A2 theA2 ) { return null; };
36 public Object methodB( Object theObj, A3 theA3 ) { return null; };
37
38 }
39
40 private Mock myCalleeMock;
41 private Callee myCallee;
42
43
44 /***
45 * {@inheritDoc}
46 */
47 protected void setUp() throws Exception {
48 super.setUp();
49
50 myCalleeMock = mock( Callee.class );
51 myCallee = (Callee) myCalleeMock.proxy();
52 }
53
54
55 /***
56 * {@inheritDoc}
57 */
58 protected void tearDown() throws Exception {
59 super.tearDown();
60 }
61
62 /***
63 * @throws Throwable ...
64 */
65 public void testA1() throws Throwable {
66 A a = new A1();
67
68 myCalleeMock.expects( once() ).method( "methodA" ).with( isA( A1.class ) );
69
70
71 MultiDispatch.dispatch( myCallee, "methodA", a );
72 }
73
74 /***
75 * @throws Throwable ...
76 */
77 public void testA2() throws Throwable {
78 A a = new A2();
79
80 myCalleeMock.expects( once() ).method( "methodA" ).with( isA( A2.class ) );
81
82
83 MultiDispatch.dispatch( myCallee, "methodA", a );
84 }
85
86 /***
87 * @throws Throwable ...
88 */
89 public void testA3() throws Throwable {
90 A a = new A3();
91
92 myCalleeMock.expects( once() ).method( "methodA" ).with( isA( A3.class ) );
93
94
95 MultiDispatch.dispatch( myCallee, "methodA", a );
96 }
97
98 /***
99 * @throws Throwable ...
100 */
101 public void testB1() throws Throwable {
102 A a = new A1();
103
104 myCalleeMock.expects( once() ).method( "methodB" ).with( new IsNull(), isA( A1.class ) );
105
106
107 MultiDispatch.dispatch( myCallee, "methodB", null, a );
108 }
109
110 }